﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Web.Admin.ashx
{
    /// <summary>
    /// upload 的摘要说明
    /// </summary>
    public class upload : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {
        /// <summary>
        /// 上传插件
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {

            if (!Evan.Member.Administrator.IsAdminLogin())
            {
                context.Response.StatusCode = 404;
                context.Response.End();
            }

            //string return_str = "";
            ////这边是FormData对象上传过来的处理
            //HttpFileCollection files = context.Request.Files;
            //foreach (string str in files)
            //{
            //    try
            //    {
            //        HttpPostedFile FileSave = files[str];  //用key获取单个文件对象HttpPostedFile

            //        byte[] FileByte = new byte[2];
            //        FileSave.InputStream.Read(FileByte, 0, 2);
            //        string ByteStr = string.Concat(FileByte.Select(res => string.Format("{0:X2} ", res))).Replace(" ", "");

            //        string FileName = DateTime.Now.ToString("yyyyMMddhhmmss_ffffff");
            //        string _FileExt = files.Get(str).FileName;
            //        _FileExt = _FileExt.Substring(_FileExt.LastIndexOf('.'), _FileExt.Length - _FileExt.LastIndexOf('.'));
            //        string FilePath = "/uploads/" + FileName + _FileExt;// +"_" + files.Get(str).FileName;

            //        string AbsolutePath = context.Server.MapPath(FilePath);
            //        FileSave.SaveAs(AbsolutePath);              //将上传的东西保存
            //        return_str = FilePath;

            //    }
            //    catch
            //    {
            //        return_str = "ERROR=上传出错";
            //    }
            //}


            Evan.Plugins.Upload.fileItemModel imageItemModel = Evan.Plugins.Upload.UploadProcess(context);
            context.Response.Write(Evan.Plugins.Upload.ConvertUploadResult(imageItemModel));

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}